package com.situ.day38;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class GenericDemo3 {
    public void add1(List<?> list) {
        //list.add(1);
        for (Object object : list) {
            System.out.println(object);
        }
    }

    public void add(List<? extends Number> list) {

    }

    @Test
    public void test1() throws Exception {
        List<Double> list1 = new ArrayList<Double>();
        List<Float> list2 = new ArrayList<Float>();
        List<Integer> list3 = new ArrayList<Integer>();
        List<String> list4 = new ArrayList<String>();
        add(list1);
        add(list2);
        add(list3);
        //add(list4);
    }

    public void save(List<? super String> list) {
    }

    @Test
    public void testGeneric24() throws Exception {
        // 调用上面方法，必须传入String的父类
        List<Object> list1 = new ArrayList<Object>();
        List<String> list2 = new ArrayList<String>();

        List<Integer> list3 = new ArrayList<Integer>();
        save(list1);
        save(list2);
    }
}
